
*********************************************************************************
** MASTER DO FILE
*********************************************************************************

	set more off
	set graph off

	** Directories
		
		** Note: Set working directory using path to where the replication folder is stored
			
			global dir " "
		
	** Install commands
	
		** Note: Install the below to run certain do files, if necessary
			
			*ssc install shp2dta
			*ssc install egenmore
			*ssc install _gwtmean
			*ssc install spmap
			*ssc install texsave
			
*********************************************************************************
*********************************************************************************

	** Clean country-level data
	
		*qui do "$dir/code/cleaning/countries/clean_countries.do"

			// purpose:  calls on do files to clean and append all waves
			
	** Compile country-level weights
	
		*qui do "$dir/code/cleaning/countries/compile_weights.do" 
		
			// purpose:  compile weights for all country-survey waves
			// uses: 	 all raw data
			// produces: weights.dta

	** Clean population projections
			
		qui do "$dir/code/cleaning/population_projections_selectcountries.do" 
		
			// purpose:  clean current and projected populations for the selected countries and regions
			// uses: 	 all raw data
			// produces: population_selectcountries.dta
			// 			 population_5yr_selectcountries.dta
			// 			 population_10yr_selectcountries.dta
			// 			 population_projections_selectcountries.dta
			
		qui do "$dir/code/cleaning/population_projections_allcountries.do"
		
			// purpose:  clean current and projected populations for all countries and regions
			// uses: 	 all raw data 
			// produces: population_projections_allcountries.dta			

	** Append country-level data, produce databases of means for figures
			
		* qui do "$dir/code/cleaning/countries/append_countries.do" 
			// purpose:  append all of the above country-level data
			// uses: 	 all cleaned country-level data
			//			 weights.dta
			// 			 population_selectcountries.dta
			// 			 population_5yr_selectcountries.dta
			// 			 population_10yr_selectcountries.dta
			// produces: allcountries.dta
			
		qui do "$dir/code/cleaning/collapse_countries.do"
			// purpose:	 collapse the data (with weights) for figures
			// uses: 	 allcountries.dta
			// produces: allcountries_means5year_weightspopsurvey.dta
			// 			 allcountries_means5year_weightspopsurvey_countries.dta
			// 			 allcountries_means5year_weightspopsurvey_all.dta
			// 			 allcountries_means5year_noweights.dta
			
	** Clean inputs for Africa map 
	
		qui do "$dir/code/cleaning/geography.do" 
			// purpose:  for generating the map
			// uses:	 mostly raw data
			//			 merges in population_projections_selectcountries.dta
			// produces: Africa_Boundaries_data.dta
			//			 Africa_Boundaries_coord.dta
			//			 Africa_Boundaries_data_labels.dta
			
	** Clean life expectancies

		qui do "$dir/code/cleaning/lifeexpectancy_2000.do"
			// purpose:  clean life expectances for selected countries in 2000
			// uses: 	 only raw data
			// produces: lifeexpectancy2000.dta
			
		qui do "$dir/code/cleaning/lifeexpectancy_2019.do"
			// purpose:  clean life expectances for selected countries in 2019
			// uses: 	 only raw data
			// produces: lifeexpectancy2019.dta
			
	** Clean summary indicators
	
		qui do "$dir/code/cleaning/summary_indicators.do"
			// purpose:  clean summary indicators for figures
			// uses:	 mostly raw data
			//			 lifeexpectancy2000.dta
			//			 lifeexpectancy2019.dta
			// produces: summaryindicators.dta
			
	** Analysis for paper
	
		qui do "$dir/code/analysis/paper_map.do"
			// purpose:  produce the map for paper
			// uses: 	 population_projections_selectcountries.dta
			// 			 Africa_Boundaries_data.dta
			//			 Africa_Boundaries_coord.dta
			
		qui do "$dir/code/analysis/paper_figure1a.do"
			// purpose:  produce the data for figure 1, panel A
			// uses:     mostly raw data
			//			 population_projections_selectcountries.dta 
			// produces: fig1a.tex
		
		do "$dir/code/analysis/paper_stats.do"
			// purpose:  compute statistics used in the text
			// uses: 	 some raw data
			//			 allcountries.dta
			// produces: --
			
		do "$dir/code/analysis/paper_stats_lifeexpectancies.do"
			// purpose:  compute statistics used in the text
			// uses: 	 some raw data
			// produces: --
			
		do "$dir/code/analysis/paper_stats_depratios.do"
			// purpose:  compute statistics used in the text
			// uses: 	 population_projections_allcountries.dta
			// produces: --
			
			
